package com.github.llyb120.stock;

import cn.hutool.core.collection.ConcurrentHashSet;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.github.llyb120.namilite.config.NamiAuth;
import com.github.llyb120.namilite.config.NamiConfig;
import com.github.llyb120.stock.ctrl.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.sql.DataSource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import static com.github.llyb120.json.Json.a;
import static com.github.llyb120.json.Json.o;

@SpringBootApplication
@EnableScheduling
public class StockApplication {

    public static void main(String[] args) {
        SpringApplication.run(StockApplication.class, args);
    }


    @Bean
    public NamiConfig namiConfig(){
        return new NamiConfig() {
            @Override
            public String[] hotPackages() {
                return new String[]{
                    "com.github.llyb120.stock.ctrl"
                };
            }

            //            @Override
//            public String controlPackages() {
//                return
//                    "com.github.llyb120.stock.ctrl";
//            }
            @Override
            public String controllerPackage() {
                return "com.github.llyb120.stock.ctrl";


            }

        };
    }


//
//    @Bean(name="datasource")
//    public DataSource datasource(Environment env) {
//        HikariDataSource ds = new HikariDataSource();
//        ds.setJdbcUrl(env.getProperty("spring.datasource.url"));
//        ds.setUsername(env.getProperty("spring.datasource.username"));
//        ds.setPassword(env.getProperty("spring.datasource.password"));
//        ds.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
//        return ds;
//    }

//    @Scheduled(cron = "0 0 0 * * ?");
//    public void collect() {
//        new test().test();
//    }


//    @Configuration
//    public static class WebConfig extends WebMvcConfigurerAdapter {
//        @Override
//        public void addResourceHandlers(ResourceHandlerRegistry registry) {
//            registry.addResourceHandler("/statics/**").addResourceLocations("classpath:/statics/");
//        }
//        @Override
//        public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
//            MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
//            ObjectMapper objectMapper = jackson2HttpMessageConverter.getObjectMapper();
//
//            //json中多余的参数不报错，不想要可以改掉
//            objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//            //设置全局的时间转化
//            SimpleDateFormat smt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            objectMapper.setDateFormat(smt);
//            objectMapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));//解决时区差8小时问题
//
//
//            //设置中文编码格式
//            List<MediaType> list = new ArrayList<MediaType>();
//            list.add(MediaType.APPLICATION_JSON_UTF8);
//            jackson2HttpMessageConverter.setSupportedMediaTypes(list);
//
//
//            //生成json时，将所有Long转换成String
//            SimpleModule simpleModule = new SimpleModule();
//            simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
//            simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
//            objectMapper.registerModule(simpleModule);
//
//            jackson2HttpMessageConverter.setObjectMapper(objectMapper);
//            converters.add(0, jackson2HttpMessageConverter);
//        }
//    }
}
